 <!DOCTYPE html>
 <html lang="en">
 <head>
     <meta charset="UTF-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>登录页面</title>
     <!-- 引入样式表 -->
     <link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.css">   
 </head>
 <body>
     <div class="container">
         <div class="row">
             <div class="col-md-12">
                 <div class="col-md-6 col-md-offset-3">
                     <div class="pannel panel-danger">
                         <div class="panel-heading">
                             <h2>登录页面</h2>
                         </div>
                         <div class="panel-body">
                             <form onsubmit="login(event)">
                                 <div class="form-group">
                                     <label for="usename" class="control-label">用户名</label>
                                     <input type="text" id="username" class="form-control">
                                 </div>
                                 <div class="form-group">
                                    <label for="password" class="control-label">密码</label>
                                    <input type="text" id="password" class="form-control">
                                </div> 
                                <div class="form-group">
                                    <input type="submit" value="登录" class="btn-primary">
                                </div>
                             </form>
                         </div>
                     </div>
                 </div>
             </div>
         </div>
     </div>
     <!-- 引入jquery -->
     <script src="/node_modules/jquery/dist/jquery.js"></script>  
     <script>
         function login(e){
             e.preventDefault();   //阻止表单默认提交
             let username = $('#username').val();
             let password = $('#password').val();
              $.post('/api/login',{username,password}).then(res=>{
                  if(res.code===0){
                      location.href = '/'
                  }else{
                      alert(res.error);
                  }
              })
         }
     </script>
 </body>
 </html>